/* spearl/include/spearl/error.h 
 * 
 * This file is part of spearl. 
 * 
 * Spearl is free software: you can redistribute it and/or modify 
 * it under the terms of the GNU General Public License as published by 
 * the Free Software Foundation, either version 3 of the License, or 
 * (at your option) any later version. 
 * 
 * Spearl is distributed in the hope that it will be useful, 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
 * GNU General Public License for more details. 
 * 
 * You should have received a copy of the GNU General Public License 
 * along with spearl. If not, see <https://www.gnu.org/licenses/>
 */ 




#ifndef __SPEARL_ERROR_H
#define __SPEARL_ERROR_H

#include <spearl/sys.h>
#include <spearl/compiler.h>
#include <spearl/klist.h>

#define SPL_BAD_BRACKETS	(SPL_ERRNO - 1)
#define SPL_INVALID_LIST 	(SPL_ERRNO - 2)
#define SPL_LIST_NFOUND 	(SPL_ERRNO - 3)
#define SPL_UNEXPECTED_LIST 	(SPL_ERRNO - 4)
#define SPL_INCOMPLETE_CALL 	(SPL_ERRNO - 5)
#define SPL_UNEXPECTED_WORD 	(SPL_ERRNO - 6)
#define SPL_MACRO_NEXISTS 	(SPL_ERRNO - 7)
#define SPL_MAX_ERROR 		(SPL_ERRNO - 8)

extern char __visible *spearl_strerrors[];
/* it's not a negative number */
extern int __visible spearl_errno;

#define spearl_error(err) 	(spearl_errno = -err, -1)
#define spearl_check_errno(err)	((err) > -SPL_ERRNO && (err) < -SPL_MAX_ERROR)
static inline char *spearl_strerror(int err) {
	if (spearl_check_errno(err)) 
		return spearl_strerrors[err];
	else 
		return spearl_strerrors[0];
}

#endif

